<template>
  <div class="components-container">
    <div class="header-form">
        <div class="layui-inline">
          <label  class="layui-form-label">登记状态</label>
          <div class="layui-inline" style="margin-top:-6px">
            <el-radio-group v-model="selectDataEixend.JpmStatusEquals" @change="getData">
              <el-radio-button  :label="IchValues" class="radio">填报中</el-radio-button>
              <el-radio-button  :label="UnIchValue" class="radio">待审核</el-radio-button>
              <el-radio-button  :label="Frozen" class="radio">已冻结</el-radio-button>
              <el-radio-button  :label="UnIchValues" class="radio">已审核</el-radio-button>
              <el-radio-button  :label="cremation" class="radio">已火化</el-radio-button>
              <el-radio-button  :label="cancellation" class="radio">已注销</el-radio-button>
              <el-radio-button  :label="outage" class="radio">已外运</el-radio-button>
            </el-radio-group>
          </div>
       </div>
    </div>
    <div class="header-form">
       <!-- <el-button type="primary" @click="readDead">读取逝者身份证</el-button> -->
        <div class="layui-inline">
          <label class="layui-form-label">逝者姓名</label>
            <div class="layui-inline">
              <el-input  v-model="selectDataEixend.JpmNameEquals" placeholder="请输入逝者姓名"></el-input>
            </div>
        </div> 
        <div class="layui-inline">
          <label class="layui-form-label">证件号码</label>
            <div class="layui-inline">
              <el-input  v-model="selectDataEixend.JpmCardnoEquals" placeholder="请输入证件号码"></el-input>
            </div>
        </div>
        <div class="layui-inline">
              <label class="layui-form-label">火化日期</label>
              <div class="layui-input-inline">
                <el-date-picker v-date type="date" v-model="selectDataEixend.JpmCremationdateEquals"></el-date-picker>
              </div>
        </div>
        <div class="layui-inline" v-if="!showdz">
          <label class="layui-form-label">户籍地址</label>
            <div class="layui-inline">
              <el-input style="width:220px;" v-model="selectDataEixend.JpmDetailAddressEquals" placeholder="请输入户籍地址"></el-input>
            </div>
        </div> 
        <div class="layui-inline" v-if="showdz">
        <label class="layui-form-label">地址</label>
        <div class="layui-input-inline">
           <el-cascader  style="width:305px"  class="dz"  ref="address"  v-model="arr" :options="addressOptions" change-on-select>
           </el-cascader>    
        </div>
      </div>
          <el-button type="primary" @click="getData" :loading="this.$store.state.isloading">搜索</el-button>
          <el-button  @click="btnRepeat" >重置</el-button>
          <!-- <el-button  @click="datas" >数据</el-button> -->
    </div>
    <div>
      <ul class="toolList">
        <li><el-button type="primary" @click="getData">刷新</el-button></li>
        <!-- <li><el-button type="primary" @click="imgprint">图片打印</el-button></li> -->
        <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)" :key="index">
          <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
        </li>              
      </ul>
    </div>
    <dataTable :headList="headList" :dataList="dataList" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable>

    <informationRegistrationMain ref="simpleReg" :orderType="order" @refreshData="getData"></informationRegistrationMain>
    <informationRegistrationInfo ref="simpleReginfo" :orderType="order" @refreshData="getData"></informationRegistrationInfo>
    <printmodal ref="printPdf"></printmodal>
    <Appendixlisttwo ref="Upload"></Appendixlisttwo>
    <Appendixlists ref="UploadInfo"></Appendixlists>
    <OperationHistory ref="OperationHistory"></OperationHistory>
  </div>
</template>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
.el-button + .el-button {
  margin-left: 0;
}
.longtext {
  width: 480px;
}
.longertext {
  width: 770px;
}
.sweet-btn {
  margin-top: 20px;
}
.radio {
  margin-top: 9px;
}
</style>
<script>
import dataTable from "@/components/Table/DataTable";
import apiBase from "@/api/apiBase.js";
import { ORDER } from "@/const/orderConst.js";
import { DATESELECTMODE } from "@/const/const.js";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import { manage } from "@/mixins/managePage.js";
import { PRINT } from "@/components/Pdf/PDF.js";
import printmodal from "@/components/Pdf/Print";
import informationRegistrationMain from "./informationRegistrationMain";
import informationRegistrationInfo from "./informationRegistrationInfo";
import OperationHistory from "./OperationHistory";
import Appendixlisttwo from "./Appendixlisttwo";
import Appendixlists from "../jointPlatform/Appendixlists";
import openidentitycard from "@/utils/openIdentityCard.js";
import { identitydata } from "@/utils/openIdentityCard.js";
const IchValues = "A";
const UnIchValue = "B";
const UnIchValues = "C";
const cremation = "D";
const cancellation = "E";
const outage = "F";
const Frozen = "G";
export default {
  name: "informationRegistration",
  mixins: [manage],
  data() {
    return {
      isUseNewAddress:null,
      showdz: null,
      arr: [],
      addressOptions: [],
      pageWidth: 1200,
      printUrl: null,
      printTitle: null,
      SELFREGISTER: ORDER.SELFREGISTER,
      //户籍所在地
      ctyLists: [],
      ctyInfo: null,
      DateSelectMode: DATESELECTMODE,
      IchValues: IchValues,
      UnIchValue: UnIchValue,
      UnIchValues: UnIchValues,
      Frozen: Frozen,
      cremation: cremation,
      cancellation: cancellation,
      outage: outage,
      selectDataEixend: {
        JpmStatusEquals: null,
        JpmNameEquals: null,
        JpmCardnoEquals: null,
        JpmCremationdateEquals: null,
        JpmDetailAddressEquals: null,
        JpmSaridLike: null //传输地址选择
      },

      //编码类型
      household: [],
      causList: [],
      codeList: [],
      cause: [],
      cauinfo: [],
      szlx: [],
      ytqx: [],
      ghqx: [],
      xblx: [],
      sfzjlx: [],
      gjlb: [],
      mz: [],
      whcdlx: [],
      hyzklx: [],
      zylx: [],
      zzmmlx: [],
      hjlblx: [],
      hjszdlx: [],
      jmlx: [],
      regData: {
        REGID: null,
        REGPRPID: null,
        REGDATE: null,
        REGTIME: null,
        REGBONETYPE: null,
        REGCAUSA: null,
        REGCAUSASON: null,
        REGDEATHID: null,
        REGREGPROVEUNIT: null,
        REGDEATHADDRESS: null,
        REGYITIQX: null,
        REGGHQX: null,
        REGNAME: null,
        REGSEX: null,
        REGCARDTYPE: null,
        REGCARDNO: null,
        REGBIRTHDATE: null,
        REGNATIONALITYTYPE: null,
        REGNATION: null,
        REGCULTURALDEGREE: null,
        REGMARRIAGE: null,
        REGJOB: null,
        REGPOLITICAL: null,
        REGHOUSEHOLDTYPE: null,
        REGHOUSETYPE: null,
        REGHOUSEHOLD: null,
        REGDETAILADDRESS: null,
        REGDEATHDATE: null,
        REGISKEYPOINT: null,
        REGHANDLERNAME: null,
        REGHANDSEX: null,
        REGHANDLERCARDTYPE: null,
        REGHANDLERCARDNO: null,
        REGHANDLERHOUSEHOLD: null,
        REGHANDLERLINK: null,
        REGRELATION: null,
        REGREMARK: null
      },
      regDataTime: null,
      regTime: null,
      //火化日期
      regCremationDate: null,
    };
  },
  methods: {
    // readDead(){
    // console.log('身份证信息');
    // console.log(identitydata);
    // openidentitycard.connects();
    // },
    // datas(){
    //     var cardInfo = [];
    //     console.log('身份证信息');
    //     console.log(identitydata);
    // var index = identitydata.indexOf(":");
    // identitydata.substring(index + 1);
    //     this.cardInfo = identitydata.split(" ");
    //     console.log(this.cardInfo);

    // },
    dealData(id, option) {
      let level = "";
      for (let index = 0; index < option.length; index++) {
        if (id == option[index].value) {
          return option[index].level;
        } else if (option[index].children) {
          if (this.dealData(id, option[index].children)) {
            return this.dealData(id, option[index].children);
          }
        }
      }
    },
    //获取火化登记数据
    getData() {
      let JpmSaridLike = this.arr[this.arr.length - 1];
      let SARID = this.arr[this.arr.length - 1];
      if(this.isUseNewAddress){
        JpmSaridLike = null
      }else{
        if (JpmSaridLike) {
          let level = this.dealData(JpmSaridLike, this.addressOptions);
          switch (level) {
            case "3":
              JpmSaridLike = JpmSaridLike.substring(0, 6);
              break;
            case "4":
              JpmSaridLike = JpmSaridLike.substring(0, 9);
              break;
            case "5":
              JpmSaridLike = JpmSaridLike.substring(0, 12);
              break;
            default:
              break;
          }
        }
        SARID = null
      }
      let datas = {
        SARID: SARID,
        JpmCardnoEquals: this.selectDataEixend.JpmCardnoEquals,
        JpmNameEquals: this.selectDataEixend.JpmNameEquals,
        JpmStatusEquals: this.selectDataEixend.JpmStatusEquals,
        JpmDetailAddressEquals: this.selectDataEixend.JpmDetailAddressEquals,
        JpmSaridLike: JpmSaridLike,
        SARID:SARID
      };
      if (this.selectDataEixend.JpmCremationdateEquals) {
        datas.JpmCremationdateEquals = formatDate(
          this.selectDataEixend.JpmCremationdateEquals,
          "yyyyMMdd"
        );
      }
      let data = {
        PageIndex: this.pageOrder.currentPage,
        PageSize: this.pageOrder.pageSize,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: datas
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().JointRegistration.Query,
        res => {
          this.dataList = res.data.content.OutData;
          this.pageOrder.totalNum = res.data.content.RecordCount;
        }
      );
    },
    //获取表头
    getColumns() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Column.GetJointRegistrationColumns,
        res => {
          this.headList = res.data.content;
        }
      );
    },
    btnShow(btn) {
      if (btn == "新增" || btn == "异地火化" || btn == "导出") return true;
      // if(btn == '附件上传') return true;
      if (this.currentRow) {
        if (btn == "附件上传" || btn == "附件详情") {
          return true;
        }
      }
      if (btn == "操作历史" && this.currentRow) return true;
      if (!this.currentRow) return false;
      if (this.currentRow.JPMSTATUS == "A") {
        if(this.currentRow.JPMSTATUSDESC=="申报中"){
           if (btn == "提交"  || btn == "删除"|| btn == "受理") {
          return true;
        }
        }else{
           if (btn == "提交" || btn == "修改" || btn == "删除") {
          return true;
        }
        }
    
      }
      if (this.currentRow.JPMSTATUS == "B") {
        if (btn == "取消提交" || btn == "审核") {
          return true;
        }
      }
      if (this.currentRow.JPMSTATUS == "C") {
        if (
          btn == "取消审核" ||
          btn == "变更" ||
          btn == "审核修改" ||
          btn == "地址修改"
        ) {
          return true;
        }
      }
      if (this.currentRow.JPMSTATUS == "G") {
        if (btn == "审核") {
          return true;
        }
      }
      if (btn == "打印死亡证明") {
        return true;
      }

      // if(btn == '提交') return true;
      // if(btn == '办结') return true;
      // if(btn == '详情') return true;

      // if(btn == '修改' && this.currentRow) return true;
      // if(btn == '删除' && this.currentRow) return true;
      // if(btn == '审核' && this.currentRow) return true;
      // if(btn == '取消审核' && this.currentRow) return true;
      // if(btn == '取消提交' && this.currentRow) return true;
    },
    //功能操作
    operate(order) {
      this.order = order;
      this.dataRepeat();
      switch (this.order) {
        case "新增":
          this.$refs.simpleReg.open(this.order);
          break;
        case "异地火化":
          this.$refs.simpleReg.open(this.order);
          break;
        case "修改":
          this.$refs.simpleReg.open(this.order, this.currentRow.JPMID);
          break;
        case "受理":
          this.$refs.simpleReg.open(this.order, this.currentRow.JPMID);
          break;
        case "详情":
          this.$refs.simpleReginfo.open(this.order, this.currentRow.JPMID);
          break;
        case "审核":
          this.$refs.simpleReg.open(this.order, this.currentRow.JPMID);
          break;
        case "取消审核":
          this.cancelExamine();
          break;
        case "提交":
          this.submits();
          break;
        case "取消提交":
          this.nosubmits();
          break;
        case "删除":
          this.dataDelete();
          break;
        case "附件上传":
          this.$refs.Upload.operate(
            this.order,
            this.currentRow.JPMID,
            this.currentRow.JPMSTATUS
          );
          break;
        case "附件详情":
          this.$refs.UploadInfo.operate("附件上传", this.currentRow.JPMID);
          break;
        case "变更":
          this.$refs.simpleReg.open("变更", this.currentRow.JPMID);
          break;
        case "审核修改":
          this.$refs.simpleReg.open("审核修改", this.currentRow.JPMID);
          break;
        case "地址修改":
          this.$refs.simpleReg.open("地址修改", this.currentRow.JPMID);
          break;
        case "打印死亡证明":
          this.$refs.printPdf.open(this.order, this.currentRow.JPMID);
          break;
        case "操作历史":
          this.$refs.OperationHistory.open("操作历史", this.currentRow.JPMID);
          break;
        case "导出":
          this.exportExcel();
          break;
        default:
      }
    },
    exportExcel() {
      let JpmSaridLike = this.arr[this.arr.length - 1];
      let SARID = this.arr[this.arr.length - 1];
      if(this.isUseNewAddress){
        JpmSaridLike = null
      }else{
        if (JpmSaridLike) {
          let level = this.dealData(JpmSaridLike, this.addressOptions);
          switch (level) {
            case "3":
              JpmSaridLike = JpmSaridLike.substring(0, 6);
              break;
            case "4":
              JpmSaridLike = JpmSaridLike.substring(0, 9);
              break;
            case "5":
              JpmSaridLike = JpmSaridLike.substring(0, 12);
              break;
            default:
              break;
          }
        }
        SARID = null
      }
      let data = {
        SARID: SARID,
        JpmCardnoEquals: this.selectDataEixend.JpmCardnoEquals,
        JpmNameEquals: this.selectDataEixend.JpmNameEquals,
        JpmStatusEquals: this.selectDataEixend.JpmStatusEquals,
        JpmDetailAddressEquals: this.selectDataEixend.JpmDetailAddressEquals,
        JpmSaridLike: JpmSaridLike
      };
      if (this.selectDataEixend.JpmCremationdateEquals) {
        data.JpmCremationdateEquals = formatDate(
          this.selectDataEixend.JpmCremationdateEquals,
          "yyyyMMdd"
        );
      }
      apiBase.DoService(
        {
          PageIndex: -1,
          Data: data
        },
        apiBase.getApiAdress().JointRegistration.Query,
        res => {
          let dataAll = res.data.content.OutData;
          if (dataAll.length === 0) {
            this.$message.error("无导出数据！");
            return;
          }
          this.downloadLoading = true;
          require.ensure([], () => {
            const { export_json_to_excel } = require("@/vendor/Export2Excel");
            export_json_to_excel(this.headList, dataAll, "联办登记");
            this.downloadLoading = false;
          });
        }
      );
    },
    // imgprint(){
    //   this.$refs.simpleReg.open('1');
    // },
    //提交
    submits() {
      this.$confirm("是否提交该数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(callback => {
        var data = {
          JPMID: this.currentRow.JPMID
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().JointRegistration.Submit,
          res => {
            setTimeout(() => {
              this.getData();
            }, 1000);
          }
        );
      });
    },

    //取消提交
    nosubmits() {
      this.$confirm("是否取消提交该数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(callback => {
        var data = {
          JPMID: this.currentRow.JPMID
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().JointRegistration.CancelSubmit,
          res => {
            this.getData();
          }
        );
      });
    },

    //登记删除
    dataDelete() {
      this.$confirm("是否删除该数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(callback => {
        var data = {
          JPMID: this.currentRow.JPMID
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().JointRegistration.Delete,
          res => {
            this.getData();
          }
        );
      });
    },
    //取消审核
    cancelExamine() {
      this.$confirm("确定取消审核吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(callback => {
        var data = {
          JPMID: this.currentRow.JPMID
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().JointRegistration.CancelVerify,
          res => {
            this.getData();
          }
        );
      });
    },
    //一键删除

    //获取地址

    restructur(value) {
      let arr = JSON.parse(JSON.stringify(value));
      var data = [];
      arr.forEach(item => {
        if (item.Children.length > 0) {
          data.push({
            label: item.SARNAME,
            value: item.SARID,
            level: item.SARLEVEL,
            children: this.restructur(item.Children)
          });
        } else {
          data.push({
            label: item.SARNAME,
            value: item.SARID,
            level: item.SARLEVEL
          });
        }
      });
      return data;
    },

    //查询条件重置
    btnRepeat() {
      // Object.assign(this.$data.selectData, this.$options.data().selectData);
      this.selectDataEixend.JpmCardnoEquals = null;
      this.selectDataEixend.JpmCremationdateEquals = null;
      this.selectDataEixend.JpmNameEquals = null;
      this.selectDataEixend.JpmDetailAddressEquals = null;
      this.selectDataEixend.JpmStatusEquals = this.IchValues;
      this.selectDataEixend.JpmSaridLike = null;
      this.arr = [];
      this.getData();
    },
    //数据重置
    dataRepeat() {
      Object.assign(this.$data.regData, this.$options.data().regData);
      this.causList = [];
      this.ctyLists = [];
      this.regDataTime = null;
      this.cauinfo = [];
    }
  },
  mounted() {
    this.selectDataEixend.JpmStatusEquals = this.IchValues;
  },
  components: {
    dataTable,
    informationRegistrationMain,
    informationRegistrationInfo,
    printmodal,
    Appendixlisttwo,
    OperationHistory,
    Appendixlists
  },
  activated() {
    this.getData();
    //控制地址下拉显隐
    apiBase.DoService({}, apiBase.getApiAdress().Param.GetIsBySar, res => {
      let show = res.data.content;
      this.showdz = show;
    });
    // 获取级联选择
    apiBase.DoService({}, apiBase.getApiAdress().Code.GetBoroughByCode, res => {
      let data = res.data.content;
      this.addressOptions = data.map(item => ({
        label: item.SARNAME,
        value: item.SARID,
        level: item.SARLEVEL,
        children: item.Children.map(item => ({
          label: item.SARNAME,
          value: item.SARID,
          level: item.SARLEVEL,
          children: this.restructur(item.Children)
        }))
      }));
    });
  },
  created() {
    this.getColumns();
    //调高拍仪
    apiBase.DoService({}, apiBase.getApiAdress().Param.GetHighmeter, res => {
      ORDER.Highmeter = res.data.content;
    });
    //是否启用新的联办地点查询（舟山联办）
    apiBase.DoService({}, apiBase.getApiAdress().Param.GetIsUseNewAddress, res => {
      this.isUseNewAddress = res.data.content;
    });
    // console.log(1);
    //  openidentitycard.connects();
    // this.getBussType();
    // this.getHousehold();
  },
  watch: {}
};
</script>
